<?php require_once('../../../Connections/ocmanmanager.php');
    require_once('../../../Connections/checkuser.php'); ?>
<?php


$colname_project = "-1";
if (isset($_GET['id'])) {
  $colname_project = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_project = sprintf("SELECT * FROM projects WHERE id = %s", GetSQLValueString($colname_project, "int"));
$project = mysql_query($query_project, $ocmanmanager) or die(mysql_error());
$row_project = mysql_fetch_assoc($project);
$totalRows_project = mysql_num_rows($project);

$colname_contract = "-1";
if (isset($_GET['id'])) {
  $colname_contract = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_contract = sprintf("SELECT * FROM contracts WHERE projectid = %s", GetSQLValueString($colname_contract, "int"));
$contract = mysql_query($query_contract, $ocmanmanager) or die(mysql_error());
$row_contract = mysql_fetch_assoc($contract);
$totalRows_contract = mysql_num_rows($contract);

$colname_projectcosts = "-1";
if (isset($_GET['id'])) {
  $colname_projectcosts = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_projectcosts = sprintf("SELECT * FROM projectcosts WHERE id = %s", GetSQLValueString($colname_projectcosts, "int"));
$projectcosts = mysql_query($query_projectcosts, $ocmanmanager) or die(mysql_error());
$row_projectcosts = mysql_fetch_assoc($projectcosts);
$totalRows_projectcosts = mysql_num_rows($projectcosts);

$colname_projectpaymenttotals = "-1";
if (isset($_GET['id'])) {
  $colname_projectpaymenttotals = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_projectpaymenttotals = sprintf("SELECT * FROM projectpaymenttotals WHERE projectid = %s", GetSQLValueString($colname_projectpaymenttotals, "int"));
$projectpaymenttotals = mysql_query($query_projectpaymenttotals, $ocmanmanager) or die(mysql_error());
$row_projectpaymenttotals = mysql_fetch_assoc($projectpaymenttotals);
$totalRows_projectpaymenttotals = mysql_num_rows($projectpaymenttotals);

$colname_project_issues = "-1";
if (isset($_GET['id'])) {
  $colname_project_issues = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_project_issues = sprintf("SELECT * FROM issuetable WHERE projectid = %s ORDER BY datecreated DESC", GetSQLValueString($colname_project_issues, "int"));
$project_issues = mysql_query($query_project_issues, $ocmanmanager) or die(mysql_error());
$row_project_issues = mysql_fetch_assoc($project_issues);
$totalRows_project_issues = mysql_num_rows($project_issues);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ozcrete Mobile - Project</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
</head>
<body>
<div id="page" data-role="page" data-theme="b">
  <div data-role="header">
    <h1>Project</h1>
  </div>
  <div class="ui-grid-a">
    <div class="ui-block-a" style="width:30%;">
      <ul data-role="listview" data-split-icon="arrow-r" data-theme="c">
        <li><a href="index.php">Projects</a></li>
        <li><a href="../issues/index.php">Issues</a></li>
                
      </ul>
    </div>
    
    <div class="ui-block-b" style="width:70%;">
      <div data-role="content">
        <ul data-role="listview" data-theme="d" data-divider-theme="d">
          <li data-role="list-divider">Details</li>
          <li>
            <h3><?php echo $row_project['projectname']; ?></h3>
            <p><strong>Date Started:<?php echo $row_project['datestarted']; ?><br>
              Date Completed:<?php echo $row_project['datecompleted']; ?><br>
              Costs: $<?php echo number_format($row_projectcosts['invin'],2,'.',','); ?><br>
              Invoice/Claims: $<?php echo number_format($row_projectcosts['invout'],2,'.',','); ?><br>
              Payments: $ <?php echo number_format($row_projectpaymenttotals['totalpaidexgst'],2,'.',','); ?><br>
              </strong><strong> Notes: </strong><strong><br>
              </strong> <?php echo $row_project['notes']; ?></p>
            <p>&nbsp;</p>
          </li>
        
          <?php if ($totalRows_project > 0) { // Show if recordset not empty ?>
            <li data-role="list-divider">Linked Contract</li>
            <li><a href="contract.php?id=<?php echo $row_contract['id']; ?>">
              <h3><?php echo $row_contract['contractname']; ?></h3>
              <p><strong><?php echo $row_contract['contract_description']; ?></strong></p>
              <p></p>
              </a></li>
            <?php } // Show if recordset not empty ?>
          <?php if ($totalRows_project_issues > 0) { // Show if recordset not empty ?>
            <li data-role="list-divider">Current Issues<span class="ui-li-count"><?php echo $totalRows_project_issues; ?></span></li>
            <?php do { ?>
              <li><a href="../issues/index.php?id=<?php echo $row_project_issues['id']; ?>">
                <h3><?php echo $row_project_issues['issuetitle']; ?></h3>
                <p><strong><?php echo strip_tags(substr($row_project_issues['issuedescription'],0,255)); ?></strong></p>
                <p><?php echo strip_tags(substr($row_project_issues['notes'],0,255))."..."; ?></p>
                <p class="ui-li-aside"><strong><?php echo date('d/m/Y',strtotime($row_project_issues['datecreated'])); ?></strong></p>
                </a></li>
              <?php } while ($row_project_issues = mysql_fetch_assoc($project_issues)); ?>
            <br />
            <?php } // Show if recordset not empty ?>
        </ul>
      </div><!-- content -->
    </div>
  </div>
  <!-- /grid-a -->
  
  <!--div data-role="footer">
    <h4>Ozcrete Pools</h4>
  </div-->
</div>
</body>
</html>
<?php
mysql_free_result($project);

mysql_free_result($contract);

mysql_free_result($projectcosts);

mysql_free_result($projectpaymenttotals);

mysql_free_result($project_issues);
?>
